import { createSlice } from "@reduxjs/toolkit";

const counterSlice = createSlice({
    name: "Counter",
    initialState: {
        count: 100,
    },
    reducers: {
        increment: (state, action) => {
            const { payload } = action;
            state.count += payload;
        },
    },
});

const { increment } = counterSlice.actions;

// 异步操作
const asyncincrement = (payload) => {
    return (dispatch) => {
        setTimeout(() => {
            dispatch(increment(payload));
        }, 200);
    };
};

export { increment, asyncincrement };
export default counterSlice.reducer;
